#include "PauseState.h"
//SGD Wrappers
#include "../../SGD_Wrappers/CSGD_Direct3D.h"
#include "../../SGD_Wrappers/CSGD_DirectInput.h"
#include "../../SGD_Wrappers/CSGD_TextureManager.h"
#include "../../SGD_Wrappers/CSGD_XAudio2.h"
#include "../../SGD_Wrappers/SGD_String.h"
#include "../../SGD_Wrappers/CSGD_EventSystem.h"
#include "../Game.h"
#include "GamePlayState.h"
#include "SettingState.h"
#include "MainMenuState.h"
#include "../DrawText.h"

CPauseState::CPauseState()
{
	m_nCursorPos = 1;
	m_nTextImageID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("text_0.png"));

}

CPauseState::~CPauseState()
{

}

CPauseState*	CPauseState::GetInstance( void )
{
	//Store an instance in global memory
	static CPauseState s_Instance;

	//Return the instance
	return &s_Instance;
}

// IGameState Interface
void	CPauseState::Enter	( void )
{
	// Store the SGD Wrapper singletons
	m_pD3D	= CSGD_Direct3D::GetInstance();
	m_pDI	= CSGD_DirectInput::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();
	m_pXA	= CSGD_XAudio2::GetInstance();
	m_pES   = CSGD_EventSystem::GetInstance();


}

void	CPauseState::Exit	( void )
{
	
}

bool	CPauseState::Input	( void )
{
	if( m_pDI->KeyPressed( DIK_RETURN ) == true && m_nCursorPos == 1 )
	{
		CGame::GetInstance()->PopState();
	}
	else if(m_pDI->KeyPressed(DIK_RETURN) && m_nCursorPos == 2)
	{
		CGame::GetInstance()->AddState(CSettingState::GetInstance());
	}
	else if(m_pDI->KeyPressed(DIK_RETURN) && m_nCursorPos == 3)
	{
		CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
	}

	if(m_pDI->KeyPressed(DIK_DOWNARROW))
		m_nCursorPos++;
	if(m_pDI->KeyPressed(DIK_UPARROW))
		m_nCursorPos--;

	if(m_nCursorPos < 1)
		m_nCursorPos = 3;
	if(m_nCursorPos > 3)
		m_nCursorPos = 1;

	return true;
}

void	CPauseState::Update	( float fElaspedTime )
{

}

void	CPauseState::Render	( void )
{
	m_pD3D->Clear(255,0,255);
	CDrawText::GetInstance()->Print(m_nTextImageID,"Pause", 20, 20,1.0f, D3DCOLOR_ARGB(255, 140, 0,0) );
		RECT Cursor = {0,0,0,0};
	if(m_nCursorPos == 1)
	{
		Cursor.left = 50;
		Cursor.top = 100;
		Cursor.bottom = 130;
		Cursor.right = 90;
		m_pD3D->DrawRect(Cursor,0,255,255);
	}

	if(m_nCursorPos == 2)
	{
		Cursor.left = 50;
		Cursor.top = 180;
		Cursor.bottom = 210;
		Cursor.right = 90;
		m_pD3D->DrawRect(Cursor,0,255,255);
	}

	if(m_nCursorPos == 3)
	{
		Cursor.left = 50;
		Cursor.top = 260;
		Cursor.bottom = 290;
		Cursor.right = 90;
		m_pD3D->DrawRect(Cursor,0,255,255);
	}

	CDrawText::GetInstance()->Print(m_nTextImageID,"Resume",100,100,1.0f,D3DCOLOR_ARGB(255, 140, 0,0));
	CDrawText::GetInstance()->Print(m_nTextImageID,"Settings",100,180,1.0f,D3DCOLOR_ARGB(255, 140, 0,0));
	CDrawText::GetInstance()->Print(m_nTextImageID,"Quit",100,260,1.0f,D3DCOLOR_ARGB(255, 140, 0,0));
}

void CPauseState::HandleEvent(CEvent* pEvent)
{

}

